  <?php if(!empty($id)) { ?>
 <form action="<?= $admin_base_url; ?>group/permission/<?=$id;?>/<?php echo $cur_page;?>" method="post" id="group_form">
 <?php } else { ?>
 <form action="<?= $admin_base_url; ?>group/permission/<?= $cur_page;?>" method="post" id="group_form">
 <?php } 
 if(!empty($group))
 {
 ?>
 
 
 <table id="tbllist">
 <tr>
 <?php 
 //print_r($flag);
 //print_r($permission);
 $count= count($group);
 $count++;
 array_unshift($permission, " ");
 $j=0;$i=0;
 foreach($permission as $p)
 {
	 echo "<tr>";
	  echo "<th width='150'>". $p['name']." </th>";
	  
	 foreach($group as $g)
 {
	 //if($i==0)
	 //echo "<td>". $g['name']." </td>";
	 if($j==0)
	 echo "<th>". $g['name']." </th>";
	 else{
	 echo "<td> ";
	 ?>
     <input type="hidden" name="group_id<?=$i ?>" value='<?=$g['id']?>'/>
     <input type="hidden" name="permission_id<?=$i ?>" value='<?=$p['id']?>'/>
     
     <?php
	 echo "<input  ";
	 if($flag[$g['id']][$p['id']]==1) echo "checked";
	 echo " type='checkbox' name='flag".$i."' value='1'/></td>"; }
	 
	 $i++;
	 
 }
 $j++;
 echo "</tr>";
	 //echo "<td>". $p['name']." </td>"; 
 }
 ?>
 </tr>
 <tr>
 <td colspan="<?=$count; ?>">
 <div class="buttons">
			    <button type="submit" name="save" class="positive" value="save" >
			        <img src="<?php echo $admin_image_path?>icons/apply.png" alt=""/>
			          <?php if(!empty($id)) { ?>
 							Update Permission
 							<input type="hidden" name="id" value="<?php echo $id;?>" />
                       
 							<input  type="hidden" name="rurl" value="<?php echo $rurl;?>" />
 					  <?php } else { ?>
 					  	Add Permission
 					  	<?php } ?>

 			    </button>
			   <a href="<?= $admin_base_url; ?>group/cancel?rurl=<?php echo $rurl;?>" class="negative">
			        <img src="<?php echo $admin_image_path?>icons/cross.png" alt=""/>
			        Cancel
			   </a>
			</div>
  </td>
 </tr>
 </table>

 </form>
 <?php
 }
 ?>
 
 <script>
 $(document).ready(function() {
     $("#group_form").RSV({
       onCompleteHandler: frmSubmit,
       errorFieldClass: "errorDesc",
       displayType: "display-html",
       errorHTMLItemBullet: "&#8212; ",
             rules: [
                     "required,name,Please enter name."
             ]
     });
  // a custom onComplete handler to prevent form submits for the demo
     function frmSubmit()
     {
       return true;
     }

        
});
 </script>